package com.terrynoya.fight.stateMachine.controllers
{
	import com.terrynoya.fight.char.Character;
	import com.terrynoya.fight.combat.Helper;
	import com.terrynoya.fight.combat.HelperData;
	import com.terrynoya.fight.stateMachine.StateController;
	import com.terrynoya.fight.util.Misc;
	import com.terrynoya.geom.MVector2D;
	
	public class HelperCtrl extends StateController
	{
		private var _helperId:int;
		private var _helperName:String;
		private var _stateId:int;
		private var _helperType:int;
		private var _posType:int;
		private var _creationOffset:MVector2D;
		
		
		public function HelperCtrl(name:String)
		{
			super(name);
		}
		
		override public function build():void
		{
			this._helperId = this.getAttributeAsInt("ID");
			this._helperName = this.getAttribute("name");
			this._stateId = this.getAttributeAsInt("stateno");
			this._helperType = Misc.getHelperType(this.getAttribute("helpertype"));
			this._posType = Misc.getPositionType(this.getAttribute("postype"));
			this._creationOffset = Misc.getVelocity(this.getAttribute("pos"));
		}
		
		override public function run(character:Character):void
		{
			var data:HelperData = new HelperData();
			data.name = this._helperName;
			data.helperId = this._helperId;
			data.initialStateId = this._stateId;
			data.type = this._helperType;
			data.positionType = this._posType;
			data.creationOffset = this._creationOffset;
			
			var helper:Helper = new Helper(character.engine,character,data);
			helper.engine.entities.add(helper);
		}
	}
}